<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <meta name="renderer" content="webkit">
    <title>宾客入住</title>
    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="../../css/base.css">
    <link rel="stylesheet" type="text/css" href="../../fonts/iconfont.css">
    <script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <script src="../../framework/cframe.js"></script>
    <!-- 仅供所有子页面使用 -->
    <!-- 公共样式 结束 -->
</head>

<body>
<fieldset class="layui-elem-field site-demo-button">
    <legend style="text-align:center;">房间总览</legend>
    <!--动态获取-->
    <div class="layui-row" id="viewRoom">
        <div class="layui-col-xs2">
            <div class="grid-demo grid-demo-bg1">
                <button type="button" class="layui-btn layui-btn-warm">维修中</button>
            </div>
        </div>
    </div>
    <!--动态获取结束-->
</fieldset>

<!--  分割线---------  -->
<fieldset class="layui-elem-field site-demo-button">
    <legend style="text-align:center;">散客/团队入住登记</legend>
</fieldset>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">选中房间办理入住</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中房间数</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
</script>


<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/room/availableRoom'
            ,toolbar: '#toolbarDemo'
            ,title: '可住房间表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'roomnum', title: '可入住房间号', width: 120, fixed: 'left', unresize: true, sort: true}
                , {field: 'roomtype', title: '房间类型', width: 90, templet: function (d) {
                        return d.roomtype ? (d.roomtype.type || '') : '';
                    }}
                , {field: 'roomtype', title: '房间价格', width: 90, templet: function (d) {
                        return d.roomtype ? ('&yen;'+ d.roomtype.price || '') : '';
                    }}
                , {field: 'roomtype', title: '容纳人数', width: 90, templet: function (d) {
                        return d.roomtype ? (d.roomtype.contain || '') : '';
                    }}
                , {field: 'roomtype', title: '押金', width: 90, templet: function (d) {
                        return d.roomtype ? ('&yen;'+d.roomtype.deposit || '') : '';
                    }}
                ,{field:'location', title:'房间位置', width:120}
                ,{field:'phone', title:'房间电话', width:120}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                //获取选择数据 并取出需要的房间id
                case 'getCheckData':
                    var data = checkStatus.data;
                    //打开子页面
                    layer.open({
                        type: 2,
                        title: '办理入住页面',
                        maxmin: true,
                        shadeClose: true, //点击遮罩关闭层
                        area : ['800px' , '520px'],
                        content: '../indent/newOrder.html',
                        //向子页面传参
                        success:function (layero,index) {

                            var iframe = window['layui-layer-iframe' + index];
                            iframe.child(JSON.stringify(data));
                        }

                    });
                    break;

                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.roomnum + ' 的查看操作');
            }
        });
    });
</script>

<!--加载自定义的sj文件  如调用加载房间 子页面-->
<script src="../../js/order/viewRoom.js"></script>
</body>
</html>